<%@ page import="cz.tpj.logic.*" %>
<%@page import="java.util.ArrayList"%>
<%@page import="cz.tpj.database.aktivity.Aktivita"%>
<%@page import="cz.tpj.database.aktivity.Table_Aktivita"%>
<%@page import="java.util.Iterator"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
final String ACTION = "action";
final String SELECTED_ACTIVITIES = "selected_activities[]";
//nacte vsechny vybrane aktivity
String[] selectedAct = request.getParameterValues(SELECTED_ACTIVITIES);
%>


<%@page import="cz.tpj.database.bod_zaujmu.Bod_zaujmu"%>
<%@page import="cz.tpj.database.bod_zaujmu.Table_Bod_zaujmu"%><html>
    <%= Navigation.getHead(null) %>
    <%= Navigation.getStartBody() %>
    <%= Navigation.getNavigationPanel(null, request) %>
          
        <div id="<%= Navigation.DIV_CENTER %>">
            <h1>Aktivity</h1>
            <hr width="470" />
            <p>
           		Prosím vyberte si z následujících aktivit: 
          	</p>
          	<!-- ************************zacatek formulare************************************ -->
          	<form action="<%= Navigation.JSP_ACTIVITIES %>" method="POST">
				<%
				//nacti vsechny aktivity
				ArrayList<Aktivita> activitiesNames = Table_Aktivita.getInstance().getAktivity();
				Iterator<Aktivita> it = activitiesNames.iterator();
				Aktivita a;
				//projdi jejich nazvy a zobraz je jako checkBoxy
				while(it.hasNext()){
					//dalsi aktivita
					a = it.next();
					//1) aktivita byla drive vybrana, pak ji nastav jako zaskrtnutou
					//2) aktivita nebyla vybrana, pak ji nezaskrtavej
					if(a.imSelected(selectedAct)){
						%>
						<input type="checkbox" 
							   name="<%= SELECTED_ACTIVITIES %>" 
							   value="<%= a.getId() %>" checked/><%= a.getNazov() %><br/>
						<%
					}else{
						%>
						<input type="checkbox" 
							   name="<%= SELECTED_ACTIVITIES %>" 
							   value="<%= a.getId() %>" /><%= a.getNazov() %><br/>
						<%	
					}
				}
				%>
				<input type="submit"   name="<%= ACTION %>" value="vyhledej"/>
			</form>
			<!-- ************************konec formulare************************************ -->
          	<hr width="470" />
          	<%
          	String action = request.getParameter(ACTION);
          	if(action != null){
          		//1) jevybrana alespon jedna akce
          		//2) neni vybrana ani jedna akce
          		if(selectedAct != null){
          			ArrayList<Bod_zaujmu> attractiv = Table_Bod_zaujmu.getInstance().getAktivita_Body(selectedAct);
          			Iterator<Bod_zaujmu> attractivePlace = attractiv.iterator();
          			Bod_zaujmu b;
          			while(attractivePlace.hasNext()){
          				b = attractivePlace.next();
          				%>
          				<h2><%= b.getNazov() %></h2>
          				<p><%= b.getKratkyPopis() %></p>
          				<p><%= b.getDlhyPopis() %></p>
          				<hr width="200" />
          				<%
          			}
          		}else{
          			out.println("<p>Pro zobrazení je zapotřebí vybrat alespoň jednu aktivitu!</p>");
          		}	
          	}
          	
          	/*
          	String action = request.getParameter(ACTION);
          	if(action != null){
          		if(selectedAct != null){
          			for(int i=0; i<selectedAct.length; i++){
          				out.println("<p>" + selectedAct[i] + "</p>");
          			}
          		}else{
          			out.println("<p>Pro zobrazení je zapotřebí vybrat alespoň jednu aktivitu!</p>");
          		}	
          	}
          	*/
          	%>
        </div>
 	<%= Navigation.getLoginLink(request) %>
</html>
